/**
 * Created by zhanglihe on 15/10/30.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'datepicker'
], function ($, common, ready, template, Collection, Model, dialog) {
    var other_file = 0;
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.event();
            this.fetch();
        },

        fetch: function (_args) {
            var args = _args || {};
            args.limit = 10;
            args.offset = 0;
            var _this = this;
            this.collection = new Collection({
                container: 'data-list',
                template: 'data-item',
                url: _global.url.api + 'agent/points',
                condition: args,
                model: {},
                callback: function () {
                    loaded();
                    //日期
                    $('.form_datetime').on('click', function () {
                        WdatePicker({
                            el: this.id,
                            dateFmt: 'yyyy-MM-dd',
                            maxDate: _this.collection.result._max_date
                        });
                    });
                    if ($('.form_datetime').val() == '') {
                        $('.form_datetime').val(_this.collection.result._date);
                    }
                    if (_this.collection.result.data.length == 0) {
                        $('#data-list').html('<tr><td colspan="4"><div>当前查询日期无排名结果</div></td></tr>');
                    }
                }
            });
            this.collection.fetch();
        },

        event: function () {
            var _this = this;
            /**
             * 搜索事件
             */
            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.date = $('input[name="date"]').val();
                _this.collection.reload();
            });
        },

        change: function (e) {
            this.data[$(e.target).attr('name')] = $(e.target).val();
        }

    };

    new index();

});